import { DynamicModule, Module } from '@nestjs/common';
import { ConfigureService } from './configure.service';
import { ConfigFactory, ConfigModule, ConfigModuleOptions } from '@nestjs/config';

import config from './config'


@Module({
  
})
export class ConfigureModule {
	static forRoot(load:ConfigFactory = null): DynamicModule {
		const loads:ConfigFactory[] = [config]
		if(load) {
			loads.push(load)
		}

		const options:ConfigModuleOptions = {
			isGlobal : true,
			expandVariables : true,
			load : loads,
			envFilePath : [`.env.${process.env.APP_NAME}`, `.env.${process.env.APP_NAME}.${process.env.NODE_ENV}`, '.env', `.env.${process.env.NODE_ENV}`]
		}

		return {
			global: true,
			module: ConfigureModule,
			providers: [ConfigureService],
			exports: [ConfigureService],
			imports : [
				ConfigModule.forRoot(options)
			]
		}
	  }
}